package cn.mesmile.grpc.controller;

import cn.mesmile.grpc.client.HelloClient;
import cn.mesmile.grpc.demo.Greeting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author zb
 * @date 2021/8/9 19:43
 * @Description
 */
@RequestMapping("/api/v1/grpc")
@RestController
public class GrpcServerServiceController {

    private final HelloClient helloClient;

    public GrpcServerServiceController(HelloClient helloClient) {
        this.helloClient = helloClient;
    }

    @GetMapping("/hello")
    public Object hello(){
        String firstName = "hello";
        String lastName = "world";
        List<String> nameList = new ArrayList<>(Arrays.asList("1"));

        Greeting greeting = helloClient.sendMessage(firstName, lastName, nameList);
        Map<String, Object> map = new HashMap<>(16);
        map.put("result","success");
        map.put("code", 200);
        map.put("data",greeting.getMessage());
        return map;
    }
}
